#!/bin/bash

set -ex

export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH
export XDG_RUNTIME_DIR="${SNAP_COMMON}/run"
mkdir -p "${XDG_RUNTIME_DIR}"

source $SNAP/actions/common/utils.sh

exit_if_service_not_expected_to_start k8s-dqlite

app=k8s-dqlite

set -a
if [ -e "${SNAP_DATA}/args/${app}-env" ]
then
  . "${SNAP_DATA}/args/${app}-env"
fi
set +a

declare -a args="($(cat $SNAP_DATA/args/$app))"
exec "$SNAP/bin/$app" "${args[@]}"
